07. CODE: Calculate H Values

Calculate H Values

L5 Calculate H Values

In this exercise, you will modify route_planner.h and route_planner.cpp to add a method CalculateHValue, which calculates the h-value for a given node. In this project, h-value will be computed as the euclidean distance from the node to the end node. Since the Node class has a built-in distance method, you can use that to define the CalculateHValue method.

## To complete this exercise:

  1. Add a CalculateHValue declaration to the RoutePlanner class in route_planner.h. This method will only be used in the RoutePlanner class, so it can be a private method. CalculateHValue should accept a const pointer to a RouteModel::Node object, and it should return a float.
  2. In route_planner.cpp define the CalculateHValue method. The method should return the distance from the passed argument to the end_node.

Note : Since CalculateHValue is private, there will be no tests for this exercise. The code will be tested implicitly through public functions in later tests.

Workspace

This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.

Workspace Information:

  • Default file path:
  • Workspace type: react
  • Opened files (when workspace is loaded): n/a
  • userCode:

    export CXX=g++-7
    export CXXFLAGS=-std=c++17
    cmake_tests() {
    /usr/local/bin/cmake -DTESTING="AStarStub" "$1"
    }
    export -f cmake_tests

Solution

Calculate H Value